﻿@model List<JustSiteWorker.User>
@using JustSiteWorker.Helpers
@{
    ViewBag.Title = "Admin";
    int count = 0;
}

<h2>Пользователи</h2>
<table border="0" style="width: 100%; border: 1px solid gray;">
    <thead>
        <tr>
            <th></th>
            <th>Статус</th>
            <th>Иконка</th>
            <th>Имя</th>
            <th>Именная ссылка</th>
            <th>Последняя активность</th>
            <th>Логинился</th>
        </tr>
    </thead>
    <tbody>
        @foreach (JustSiteWorker.User user in Model)
        {
            if (user.Id != (int)Session["Id"])
            {
                count++;
            <tr>
                <td>
                    <input type="checkbox" id="@user.Id" /></td>
                <td>
                    @if (Html.IsOnline(user))
                    {
                        <img src="../../Images/online.png" />
                    }
                    else
                    {
                        <img src="../../Images/offline.png" />
                    }
                </td>
                <td>
                    <img src="@user.Avatar" height="32" />
                </td>
                <td style="width: 100%; text-align: left;">
                    <a href="/Home/Statistika/@user.Id">@user.Name</a>
                </td>
                <td>
                    @Html.GetNamedLink(user, Request)
                </td>
                <td id="activity_@user.Id">
                    @if (user.LastVisit != null)
                    {
                        @Html.Raw(Html.LastUserActiv(user)) <span>
                            <img src="../../Images/trash.png" height="16" style="cursor: pointer;" onclick="clearActivity('@user.Id')" /></span>
                    }
                </td>
                <td>
                    @user.Statistika.Count
                </td>
            </tr>
            }
        }
        @if (count == 0)
        {
            <tr>
                <td colspan="7">Нету пользователей
                </td>
            </tr> 
        }
    </tbody>
    <tfoot>
        <tr>
            <td colspan="7" style="text-align: right;">Всего пользователей: @count</td>
        </tr>
    </tfoot>
</table>

<div>
    <input type="button" value="Добавть" onclick="document.location = '/Home/AddUser'" />
</div>

<script>
    function removeUser() {
        var ids = [];
        $('table input:checked').each(function () {
            ids.push($(this).attr('id'));
        });



    }

    function clearActivity(id) {
        $.ajax({
            type: "POST",
            url: "/Home/ClearActivity",
            contentType: 'application/json',
            data: JSON.stringify({ id: id }),
            success: function (response) {
                $('#activity_' + id).html("");
            }
        });
    }
</script>

<style>
    table {
        border-spacing: 0;
        border-collapse: separate;
        text-align: center;
    }

        table td, table th {
            padding: 8px;
        }


        table th, table td {
            border-bottom: 1px solid gray;
            /*border-right: 1px solid gray;*/
        }

            table th:last-child {
                border-right: 0 solid gray;
            }


        table tfoot tr td {
            /*border-top: 1px solid gray;*/
            color: gray;
        }

            table tfoot tr td:last-child {
                border-bottom: 0 solid gray;
            }
</style>
